package com.huilunyingshi.videoconsumer.controller;

import com.huilunyingshi.videoapi.service.TFilmService;
import com.hullunyingshi.until.ControllerResult;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@Slf4j
@Scope("prototype")
@RestController
@RequestMapping("/Film")
public class FilmController {
	 private final Logger logger = LoggerFactory.getLogger(FilmController.class);
	 
	 @Autowired
	 private TFilmService tFilmService;


	    @ApiOperation(value = "分页查询film列表", notes = "分页查询film列表")
	    @ApiImplicitParams({
	            @ApiImplicitParam(name = "keyword", value = "film名", paramType = "query", dataType = "String", required = false),
	            @ApiImplicitParam(name = "curPage", value = "当前页", paramType = "query", dataType = "int", required = false)
	    })
	    @GetMapping ("getFilmList")
	    @ApiResponses(value = {
	            @ApiResponse(code = 200, message = "查询成功", response = ControllerResult.class),
	            @ApiResponse(code = 400, message = "查询失败", response = String.class),
	            @ApiResponse(code = 500, message = "(服务器内部错误)服务器遇到错误，无法完成请求 ", response = String.class),
	    })
		public ControllerResult getFilmList(String keyword,
                                            Integer curPage
		) throws ParseException {

			logger.info("#################### TfilmController. /Film/getFilmList" + keyword + "##" + curPage + "#######");
			try {
				return tFilmService.getFilmList(keyword, curPage);
			} catch (Exception e) {
				logger.info("#################### error 500 /Film/getFilmList" + e.getStackTrace());
				return new ControllerResult("500", "服务器错误", null);
			}
		}

	@ApiOperation(value = "查询电影", notes = "查询电影")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "电影id", paramType = "query", dataType = "long", required = false),

	})
	@GetMapping ("getFilm")
	@ApiResponses(value = {
			@ApiResponse(code = 200, message = "查询成功", response = ControllerResult.class),
			@ApiResponse(code = 400, message = "查询失败", response = String.class),
			@ApiResponse(code = 500, message = "(服务器内部错误)服务器遇到错误，无法完成请求 ", response = String.class),
	})
	public ControllerResult getAnime(Long id) throws ParseException{
		logger.info("#################### FilmController. /Film/getFilm" + id+"#######");
		try {
			return tFilmService.getFilm(id);
		} catch (Exception e) {
			logger.info("#################### error 500 /Film/getFilm" + e.getStackTrace());
			return new ControllerResult("500", "服务器错误", null);
		}

	}


	@ApiOperation(value = "查询类型电影", notes = "查询类型电影")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "lid", value = "电影类型id", paramType = "query", dataType = "long", required = false),

	})
	@GetMapping ("getFilmTypeList")
	@ApiResponses(value = {
			@ApiResponse(code = 200, message = "查询成功", response = ControllerResult.class),
			@ApiResponse(code = 400, message = "查询失败", response = String.class),
			@ApiResponse(code = 500, message = "(服务器内部错误)服务器遇到错误，无法完成请求 ", response = String.class),
	})
	public ControllerResult getFilmTypeList(Long lid,  Integer curPage) throws ParseException{
		try {
			return tFilmService.getFilmTypeList(lid,curPage);
		}catch (Exception e){
			logger.info("#################### error 500 /Film/getFilmTypeList" + e.getStackTrace());
			return new ControllerResult("500", "服务器错误", null);
		}
	}


}